#include "brickplatform.h"
#include <QPainter>

BrickPlatform::BrickPlatform(int length, QGraphicsItem *parent)
    : QGraphicsItem(parent), mLength(length)
{
    setFlag(ItemClipsToShape);
    mPixmap = QPixmap(":images/ironbrick.png"); // 加载固定砖块图
}

void BrickPlatform::nextFrame() {
}

QRectF BrickPlatform::boundingRect() const {
    return QRectF(0, 0, 48 * mLength, 48);
}

void BrickPlatform::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    Q_UNUSED(widget);
    Q_UNUSED(option);

    for (int i = 0; i < mLength; ++i) {
        painter->drawPixmap(i * 48, 0, mPixmap, 0, 0, 48, 48);
    }

    setTransformOriginPoint(boundingRect().center());
}

int BrickPlatform::type() const {
    return Type;
}
